﻿using CheckIn.ToolsHost.Applications;
using CheckIn.ToolsHost.Dtos;
using CheckIn.ToolsHost.Infrastructures;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;

namespace CheckIn.ToolsHost.Controllers
{
    public class MainController : BaseController
    {
        /// <summary>
        /// 用姓名算命
        /// </summary>
        /// <param name="xing">姓氏</param>
        /// <param name="ming">名字</param>
        /// <param name="sex">性别</param>
        /// <param name="year">出生日期-年</param>
        /// <param name="month">出生日期-月</param>
        /// <param name="day">出生日期-日</param>
        /// <param name="hourstr">出生日期-时辰</param>
        /// <returns></returns>
        public async Task<FortuneResult> FortuneByName(string xing,string ming,string sex, int year,int month,int day,string hourstr)
        {
            var tg = ChineseEraConverter.GetMonthEra(new DateTime(year, month, 1));
            var test = Global.ServiceProvider.GetService<FortuneTellingService>().FortuneTelling(xing, ming);
            test.MonthDizhi = tg.DiZhiString;
            test.MonthFiveElement = Global.ServiceProvider.GetService<FiveElementService>().GetFiveElementByChinese(tg.DiZhiString);

            var db = this.CurrentDBContext;
            db.BeginTransaction();

            int hour = 0;
            int.TryParse(hourstr, out hour);

            await db.InsertAsync(new DBModels.FortuneHistory
            {
                Xing = xing,
                Ming = ming,
                Sex = sex,
                Birthday = new DateTime(year,month , day , hour, 0,0)
            });

            return test;
        }
    }
}
